// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   SourceFile

package com.sgame.android.network;

import android.os.*;
import com.sgame.android.MLog;

import java.io.IOException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpResponseException;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.util.EntityUtils;

// Referenced classes of package com.mobage.ww.android.network:
//            HttpRequest

public class AsyncHttpResponseHandler
{

    public AsyncHttpResponseHandler()
    {
        if(Looper.myLooper() != null)
        	mHandler = new Handler() {

                public final void handleMessage(Message msg)
                {
                    a.handleMessage(msg);
                }

                final AsyncHttpResponseHandler a;

            
                {
                	a = AsyncHttpResponseHandler.this;
                }
            }
        ;
    }

    public void b()
    {
    }

    public void a()
    {
    }

    public void onSuccess(String s)
    {
    	MLog.d("AsyncHttpResponseHandler", "Empty onSuccess!");
    }

    public void onFailure(Throwable throwable)
    {
    	MLog.d("AsyncHttpResponseHandler", "Empty onFailure!");
    }

    public void onFailure(Throwable throwable, String s)
    {
    	onFailure(throwable);
    }

    protected final void onFailure(Throwable throwable, String s, HttpRequest httprequest)
    {
    	sendMessage(getMessage(1, ((Object) (new Object[] {
            throwable, s, httprequest
        }))));
    }

    protected final void sendMessage2() //c
    {
    	sendMessage(getMessage(2, null));
    }

    protected final void sendMessage3() //d
    {
    	sendMessage(getMessage(3, null));
    }

    protected final void handleMessage(Message message)
    {
        try
        {
            switch(message.what)
            {
            case 0: // '\0'
                String s = (String)message.obj;
                message = null;
                onSuccess(s);
                return;

            case 1: // '\001'
            	Object[] msg = (((Object[])message.obj));
            	onFailure((Throwable)msg[0], (String)msg[1]);
                return;

            case 2: // '\002'
                b();
                return;

            case 3: // '\003'
                a();
                break;
            }
            return;
        }
        // Misplaced declaration of an exception variable
        catch(Exception ex)
        {
            MLog.d("AsyncHttpResponseHandler", "Exception thrown while handling HTTP response: ", ex);
        }
    }

    private void sendMessage(Message message) //b
    {
        Looper.myLooper();
        Looper.getMainLooper();
        if(mHandler != null)
        {
            try
            {
            	 MLog.d("AsyncHttpResponseHandler", (new StringBuilder("Send message using handler: ")).append(message.what).toString());
            	 mHandler.sendMessage(message);
                return;
            }
            // Misplaced declaration of an exception variable
            catch(Exception ex)
            {
                MLog.d("AsyncHttpResponseHandler", "Exception thrown while handling HTTP response: ", ex);
            }
           
        } else
        {
        	MLog.d("AsyncHttpResponseHandler", (new StringBuilder("Handle message: ")).append(message.what).toString());
        	handleMessage(message);
            return;
        }
    }

    private Message getMessage(int i, Object obj)
    {
        Message message;
        if(mHandler != null)
        {
            message = mHandler.obtainMessage(i, obj);
        } else
        {
            (message = new Message()).what = i;
            message.obj = obj;
        }
        return message;
    }

    final void getHttpEntity(HttpResponse httpresponse)
    {
        StatusLine statusline = httpresponse.getStatusLine();
        try
        {
            Object obj1 = null;
            HttpEntity httpEntity;
            if((httpEntity = httpresponse.getEntity()) != null)
                obj1 = new BufferedHttpEntity(httpEntity);
            obj1 = EntityUtils.toString(((org.apache.http.HttpEntity) (obj1)));
            if(statusline.getStatusCode() >= 300)
            {
                MLog.d("AsyncHttpResponseHandler", (new StringBuilder("HTTP status indicated error: ")).append(statusline.getStatusCode()).toString());
                onFailure(((Throwable) (new HttpResponseException(statusline.getStatusCode(), statusline.getReasonPhrase()))), ((String) (obj1)), null);
                return;
            } else
            {
                MLog.d("AsyncHttpResponseHandler", "Sending success message: ");
                sendMessage(getMessage(0, obj1));
                return;
            }
        }
        catch(IOException ioexception)
        {
            MLog.d("AsyncHttpResponseHandler", "Exception thrown while sending response message: ", ioexception);
            onFailure(((Throwable) (ioexception)), null, null);
            return;
        }
    }

    private final boolean a = false;
    private Handler mHandler;
}
